var t = require("../../../@babel/runtime/helpers/defineProperty"), a = require("../../../mybehaviors/location/location"), e = getApp();

Page({
    behaviors: [ a ],
    data: {
        isshow: !1,
        poster: "",
        active: 0,
        topContent: {},
        bannerContent: {},
        functionList: {},
        cate: [],
        cateList: [],
        newClassification: "",
        nearbyClassification: "",
        address: "",
        city: "",
        point: "",
        Height: 0,
        LastHeight: 0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        getMoreDataType: "newClassification",
        cateMoreData: {},
        loading: !1,
        resizeTabs: !1,
        stroeAloneStyle: !1,
        micro_style_type: 0,
        closeNearby: !1,
        showLoading: !0
    },
    onLoad: function(t) {
        1 == e.globalData.store_alone_temp && this.setData({
            stroeAloneStyle: !0
        }), this.getHomePageData(t), this._getLocation(function(t, a) {});
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.loading ? console.log("没有更多数据") : this.getMoreData();
    },
    onShareAppMessage: function() {},
    onShareTimeline: function() {},
    openQrCode: function() {
        this.data.poster ? this.setData({
            isshow: !0
        }) : this.getPoster();
    },
    getPoster: function() {
        var t = this, a = e.getNetAddresss("member.poster");
        e._getNetWork({
            url: a,
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    poster: e.data.image_url,
                    isshow: !0
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getHomePageData: function(t) {
        var a = this, i = e.getNetAddresss("plugin.micro-communities.api.index.index");
        e._getNetWork({
            url: i,
            success: function(e) {
                var i = e.data;
                if (1 == i.result) {
                    i.data.set && (a.setData({
                        topContent: {
                            micro_top: i.data.set.micro_top,
                            micro_top_jump: i.data.set.micro_top_small,
                            browse_num: i.data.browse_num,
                            trick_num: i.data.trick_num
                        },
                        micro_style_type: i.data.set.micro_style_type
                    }), i.data.video_set && i.data.video_set.video_path && a.setData({
                        video_path: i.data.video_set.video_path
                    }), a.setData({
                        bannerContent: i.data.set
                    }), a.setData({
                        functionList: {
                            show_sign: 1 == i.data.set.show_sign,
                            show_clock: 1 == i.data.set.show_clock,
                            show_video: 1 == i.data.set.show_video,
                            show_qr: 1 == i.data.set.show_qr
                        }
                    })), a.data.closeNearby = !!i.data.nearby_close && Number(i.data.nearby_close);
                    for (var s = a.data.cateList, o = 0; o < i.data.cate.length; o++) s.push([]);
                    a.setData({
                        cate: i.data.cate,
                        closeNearby: a.data.closeNearby,
                        cateList: s
                    });
                    var n = !0;
                    if (t && t.cat_id) {
                        var c = null, d = !1;
                        a.data.cate.map(function(a, e) {
                            a.id == t.cat_id && (c = e), a.child.map(function(a) {
                                a.id == t.cat_id && (c = e, d = !0);
                            });
                        }), null !== c && (n = !1, a.setData({
                            active: a.data.closeNearby ? c + 1 : c + 2
                        }), d ? a.getCateChild(Number(t.cat_id)) : a.getClassificationBtn({
                            detail: {
                                index: a.data.active,
                                title: ""
                            }
                        }));
                    }
                    n && a.getClassification("newClassification"), a.setData({
                        resizeTabs: !0
                    });
                } else wx.showToast({
                    title: i.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getClassification: function(a, i, s) {
        var o = this, n = e.getNetAddresss(1 == e.globalData.store_alone_temp ? "plugin.store-alone-temp.frontend.microCommunities.index.getStick" : "plugin.micro-communities.api.index.getStick");
        this.pageInit();
        var c = {};
        i ? c.cat_id = i : "newClassification" == a ? c.trick_new = 1 : "nearbyClassification" == a && (c.lng = this.data.point.lng, 
        c.lat = this.data.point.lat, c.city_name = this.data.city, c.address = this.data.city), 
        c.stick_type = 1, e._postNetWork({
            url: n,
            showToastIn: !1,
            data: c,
            success: function(n) {
                o.setData({
                    showLoading: !1
                });
                var c, d = n.data;
                1 == d.result ? (o.data.total_page = d.data.last_page, i ? (o.setData((t(c = {}, "cateList[" + s + "]", d.data.data), 
                t(c, "newClassification", d.data.data), c)), console.log(o.data.cateList, o.data.newClassification, o.data.micro_style_type, "dddddddddddd")) : "newClassification" == a || 1 == e.globalData.store_alone_temp ? o.setData({
                    newClassification: d.data.data
                }) : "nearbyClassification" == a && o.setData({
                    nearbyClassification: d.data.data
                })) : wx.showToast({
                    icon: "none",
                    title: d.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    jumpToSearch: function() {
        wx.navigateTo({
            url: "/packageC/micro_communities/microSearchIndex/microSearchIndex"
        });
    },
    jumpAddress: function(t) {
        var a = t.currentTarget.dataset.url;
        a.indexOf("http") < 0 && wx.navigateTo({
            url: a
        });
    },
    goToUrl: function(t) {
        var a = t.currentTarget.dataset.name;
        "sign" == a ? wx.navigateTo({
            url: "/packageA/member/sign/sign"
        }) : "ClockPunch" == a ? wx.navigateTo({
            url: "/packageA/member/ClockPunch/ClockPunch"
        }) : "VideoList" == a && ("videoList" == this.data.video_path ? wx.navigateTo({
            url: "/packageC/video_goods/VideoList/VideoList"
        }) : "videoDetail" == this.data.video_path ? wx.navigateTo({
            url: "/packageC/video_goods/VideoDetail/VideoDetail"
        }) : wx.navigateTo({
            url: "/packageC/video_goods/VideoList/VideoList"
        }));
    },
    goClassification: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageC/micro_communities/microClassification/microClassification?cateId=" + a + "&micro_style_type=".concat(this.data.micro_style_type)
        });
    },
    jumpDetails: function(t) {
        var a = t.currentTarget.dataset.stickid;
        wx.navigateTo({
            url: "/packageC/micro_communities/microCommentDetails/microCommentDetails?stickId=" + a
        });
    },
    imgHeight: function(t) {
        var a = wx.getSystemInfoSync().windowWidth * t.detail.height / t.detail.width + "px";
        parseInt(a) > this.data.LastHeight && (this.setData({
            Height: a
        }), this.data.LastHeight = parseInt(a));
    },
    getClassificationBtn: function(a) {
        var e = a.detail.index, i = a.detail.title;
        if (this.setData({
            active: a.detail.index
        }), "最新" == i) this.getClassification("newClassification"), this.data.getMoreDataType = "newClassification"; else if ("附近" == i) this.getClassification("nearbyClassification"), 
        this.data.getMoreDataType = "nearbyClassification"; else {
            var s, o = this.data.closeNearby ? e - 1 : e - 2;
            this.getClassification("", this.data.cate[o].id, o), this.data.getMoreDataType = "cate", 
            this.setData((t(s = {}, "cateMoreData.type", ""), t(s, "cateMoreData.id", this.data.cate[o].id), 
            t(s, "cateMoreData.index", o), s));
        }
    },
    getCateChild: function(a) {
        var e, i = a.currentTarget ? a.currentTarget.dataset.id : a, s = this.data.closeNearby ? this.data.active - 1 : this.data.active - 2;
        this.getClassification("", i, s), this.data.getMoreDataType = "cate", this.setData((t(e = {}, "cateMoreData.type", ""), 
        t(e, "cateMoreData.id", i), t(e, "cateMoreData.index", s), t(e, "cateList[" + s + "]", []), 
        e));
    },
    pageInit: function() {
        this.setData({
            page: 1,
            total_page: 0,
            isLoadMore: !0,
            loading: !1,
            showLoading: !0
        });
    },
    getMoreData: function() {
        var a = this, i = {};
        "newClassification" == this.data.getMoreDataType ? i.trick_new = 1 : "nearbyClassification" == this.data.getMoreDataType ? (i.lng = this.data.point.lng, 
        i.lat = this.data.point.lat, i.city_name = this.data.city, i.address = this.data.city) : i.cat_id = this.data.cateMoreData.id, 
        this.data.isLoadMore = !1;
        var s = e.getNetAddresss("plugin.micro-communities.api.index.getStick");
        this.data.page >= this.data.total_page ? this.setData({
            loading: !0
        }) : (this.data.page = this.data.page + 1, i.page = this.data.page, i.stick_type = 1, 
        e._postNetWork({
            url: s,
            showToastIn: !1,
            data: i,
            success: function(e) {
                var i = e.data;
                if (1 == i.result) {
                    var s = i.data.data;
                    if ("newClassification" == a.data.getMoreDataType) a.setData({
                        newClassification: a.data.newClassification.concat(s)
                    }); else if ("nearbyClassification" == a.data.getMoreDataType) a.setData({
                        nearbyClassification: a.data.nearbyClassification.concat(s)
                    }); else {
                        var o;
                        a.setData((t(o = {}, "cateList[" + a.data.cateMoreData.index + "]", a.data.cateList[a.data.cateMoreData.index].concat(s)), 
                        t(o, "newClassification", a.data.newClassification.concat(s)), o));
                    }
                } else a.data.page = a.data.page - 1, a.data.isLoadMore = !1;
            },
            fail: function(t) {}
        }));
    },
    clicktapshow: function() {
        this.setData({
            isshow: !1
        });
    }
});